//
//  ELCostomTabBar.swift
//  SinaWeiBo
//
//  Created by jiwang on 15/12/15.
//  Copyright © 2015年 jiwang. All rights reserved.
//

import UIKit

class ELCostomTabBar: UITabBar {

    let subCount = 5
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let ItemW : CGFloat = self.frame.width / CGFloat(subCount)
        
        var index = 0
        
        for view in subviews {
            if view is UIControl {
                view.frame = CGRectMake(CGFloat(index) * ItemW, 0, ItemW, self.frame.height)
                
                index += index == 1 ? 2 : 1
            }
            plusBtn.frame = CGRectMake(2.0 * ItemW, 0, ItemW, self.frame.height)
        }
    }
    
    lazy var plusBtn : UIButton = {
        let button = UIButton()
        
        //设置背景
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(button)
        return button
    }()
    
}